%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "Arbre.h"
#include "y.tab.h"

int num_lines=1;
%}

%option noyywrap

Nb 		(0|[1-9][0-9]*)
id              [A-Za-z]([A-Za-z]|[0-9])*
blank           [ \t]+

%x COMBLOC COMLINE

%%

"var"        {return VAR;}
"out"        {return OUT;}
"in"         {return IN;}
"get"        {return GET;}
"<-"         {return AFFECTL;}
"->"         {return AFFECTR;}
"<->"        {return SWAP;}

"+"          {return PLUS;}
"-"          {return MINUS;}
"*"          {return TIMES;}
"/"          {return SLASHORDIV;}
"mod"        {return MODULO;}


"["          {return CL;}
"]"          {return CR;}
"("          {return LP;}
")"          {return RP;}
","          {return COMMA;}
";"          {return END;}
":"	     {return COLON;}

"&"	     {return AND;}
"|"          {return OR;}
"!"          {return NOT;}

"="          {return EQUAL;}
"<"          {return SMALLER;}
"<="         {return SMALLEQ;}
">"          {return GREATER;}
">="         {return GREATEQ;}

"if"         {return IF;}
"fi"         {return FI;}
"then"	     {return THEN;}
"else"       {return ELSE;}
"while"      {return WHILE;}
"do"         {return DO;}
"od"         {return OD;}
"return"     {return RETURN;}

"int"        {return INT;}
"bool"       {return BOOL;}
"matrix"     {return MATRIX;}
"nil"        {return NIL;}
"true"       {return TRUE;}
"false"      {return FALSE;}

"create"     {return CREATE;}
"set"        {return SET;}
"clone"      {return CLONE;}

"["{blank}*"decl"{blank}*"]"               	{return DECL;}
"["{blank}*"/decl"{blank}*"]"    		{return ENDDECL;}
"["{blank}*"code"{blank}*"]"                    {return CODE;}
"["{blank}*"/code"{blank}*"]"                   {return ENDCODE;}
"["{blank}*"lsd11"{blank}*                      {return LSD11;}   
"["{blank}*"/lsd11"{blank}*"]"                  {return ENDLSD11;}


"["{blank}*"comment"{blank}*"]"                 {BEGIN COMBLOC;}
<COMBLOC>.					{/*On passe*/}
<COMBLOC>"\n"                                   {num_lines++;}
<COMBLOC>"["{blank}*"/comment"{blank}*"]"       {BEGIN INITIAL;}

"%"      	    	{BEGIN(COMLINE);}
<COMLINE>. 		{/*On passe*/}
<COMLINE>"\n" 		{BEGIN(INITIAL);num_lines++;}

{Nb}     {
                yylval.ival=atoi(yytext);
				return NB;
         }

{id}        {
                yylval.sval=(char*)calloc(strlen(yytext)+1,sizeof(char));
				strcpy(yylval.sval,yytext);
				return ID;
             }

"\n"         {num_lines++;}

{blank}      {/*On passe*/}

.            {
                fprintf(stderr,"KO\n");
                printf("ERROR : invalid '%s' in line %d\n",yytext, num_lines);
                exit(0);
             }

%%


